package com.hllxd.hism.passport.login.gateway.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieUtil {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    public static void setCookieDomain(Cookie cookie, String domain) {
        if (!StringUtils.isEmpty(domain)) {
            cookie.setDomain(domain);
        }
    }

    public static String getCookieValue(HttpServletRequest request, String cookieKey) {
        Cookie[] cookies = request.getCookies();
        String tokenValue = null;
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(cookieKey)) {
                    tokenValue = cookie.getValue();
                    break;
                }
            }
        }
        return tokenValue;
    }
}
